package com.test.ui;

import com.test.strings.Constants;
import com.test.ui.control.UploadActivity;
import com.weibo.net.AccessToken;
import com.weibo.net.DialogError;
import com.weibo.net.Weibo;
import com.weibo.net.WeiboDialogListener;
import com.weibo.net.WeiboException;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class WeiboRelationShipsActivity extends Activity {


	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		Weibo mWeibo = Weibo.getInstance();

		mWeibo.setupConsumerConfig(Constants.APIKEY, Constants.APISECRET);
		mWeibo.setRedirectUrl("http://www.sina.com");
		
		mWeibo.authorize( WeiboRelationShipsActivity.this, new AuthDialog());

	}

	
	/**
	 * Oauth2 授权Dialog
	 * @author Administrator
	 *
	 */
	private class AuthDialog  implements WeiboDialogListener{

		@Override
		public void onCancel() {
			// TODO Auto-generated method stub

		}

		@Override
		public void onComplete(Bundle values) {

			String token = values.getString("access_token");
			String expires_in = values.getString("expires_in");

			System.out.println("获取的token:" + token );
			System.out.println("获取的expires_in:" + expires_in);

			AccessToken accessToken = new AccessToken(token, Constants.APISECRET);
			accessToken.setExpiresIn(expires_in);

			Weibo.getInstance().setAccessToken(accessToken);
			
			System.out.println("授权成功...");
			
			System.out.println("开始睡眠5秒...");
			try {
				Thread.sleep(5000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			startActivity( new Intent(WeiboRelationShipsActivity.this, UploadActivity.class));
		}

		@Override
		public void onError(DialogError e) {
			// TODO Auto-generated method stub

		}

		@Override
		public void onWeiboException(WeiboException e) {
			// TODO Auto-generated method stub

		}
	}


}